//
//  StudentDetailViewController.m
//  Eath
//
//  Created by yuhaya on 10/5/14.
//  Copyright (c) 2014 yuhaya. All rights reserved.
//

#import "StudentDetailViewController.h"
#import "Tool.h"
#import "DayPointView.h"
#import "ContentViewController.h"
#import "HistoryNavViewController.h"

@implementation StudentDetailViewController

- (void) viewDidLoad
{
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"历史信息"];
    customLab.textAlignment = NSTextAlignmentCenter;
    customLab.font = [UIFont boldSystemFontOfSize:16];
    self.navigationItem.titleView = customLab;
//    self.view.backgroundColor = [UIColor grayColor];
    UIScrollView * scrollView = [[UIScrollView alloc] init];
    UIScreen * currentScreen = [UIScreen mainScreen];
    scrollView.frame = CGRectMake(0, self.head_block.frame.size.height + 54, 320, currentScreen.applicationFrame.size.height - 80);
    scrollView.backgroundColor = [UIColor colorWithRed:0.945 green:0.945 blue:0.945 alpha:1];
    scrollView.contentSize = CGSizeMake(320, 670);
    self.constraintView = scrollView;
    [self.view addSubview:scrollView];
    
    [self.left setBackgroundImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
    [self.right setBackgroundImage:[UIImage imageNamed:@"right"] forState:UIControlStateNormal];
    self.name.text = self.stu.name;
    self.photo.image = [UIImage imageNamed:self.stu.photo];
    self.photo.layer.cornerRadius = self.photo.frame.size.width/2;
    self.photo.layer.shouldRasterize = YES;
    self.photo.layer.masksToBounds = YES;
    [self.photo.layer setBorderWidth:3];
    [self.photo.layer setBorderColor:[Tool colorWithHexString:@"#ffffff"].CGColor];
    
    self.date = [NSDate date];
    DLog(@"%@",[self.date description]);
    self.e_time.text = [Tool getDateStringWithDate:self.date DateFormat:@"yyyy-MM-dd"];
    DLog(@"%@",self.e_time.text);
    self.s_time.text = [Tool pre_week_date:self.date andFormat:@"yyyy-MM-dd"];
    [self list];
}
- (void) list
{
    for(DayPointView *view in [self.constraintView subviews])
    {
        [view removeFromSuperview];
    }
    
    NSString * s_time = self.s_time.text;
    NSString * e_time = self.e_time.text;
    self.stu.delegateDuring = self;
    [self.stu week_point_stime:s_time and_etime:e_time];
}

-(void)stuPointDuringOver:(NSMutableArray *)data;
{
    DLog(@"%@",data);
    for (int a = 0; a < data.count; a++) {
        DayPointView * pointer = [[DayPointView alloc] initWithFrame:CGRectMake(0, a*80, 320, 60) andData:data[a]];
        pointer.backgroundColor = [UIColor whiteColor];
        [pointer addTarget:self action:@selector(pointClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.constraintView addSubview:pointer];
    }
}

-(void)stuPointDuringFail
{
    
}

- (IBAction)leftClick:(UIButton *)sender {
    NSDate * pre = [Tool bre_week_date_obj:self.date];
    NSString * pre_str = [Tool getDateStringWithDate:pre DateFormat:@"yyyy-MM-dd"];
    self.e_time.text = pre_str;
    NSString * pre_monday_str = [Tool pre_week_date:pre andFormat:@"yyyy-MM-dd"];
    self.s_time.text = pre_monday_str;
    self.date = pre;
    [self list];
}

- (IBAction)rightClick:(UIButton *)sender {
    NSDate * next = [Tool next_week_date_obj:self.date];
    NSString * next_str = [Tool getDateStringWithDate:next DateFormat:@"yyyy-MM-dd"];
    self.e_time.text = next_str;
    NSString * next_monday_str = [Tool pre_week_date:next andFormat:@"yyyy-MM-dd"];
    self.s_time.text = next_monday_str;
    self.date = next;
    [self list];
}

- (void) pointClick:(DayPointView *)sender
{
    NSString * date = sender.DayDate[@"time"];
    ContentViewController * view_box = [[ContentViewController alloc] initWhithStu:self.stu andTime:[date integerValue]];
    view_box.detegate = (HistoryNavViewController *)self.navigationController;
    [self.navigationController pushViewController:view_box animated:YES];
    
}
@end